/**
 * jims
 */
package com.jims.master.modules.orders.service;

import com.google.common.collect.Lists;
import com.jims.master.common.persistence.Page;
import com.jims.master.common.service.CrudService;
import com.jims.master.common.utils.DateUtils;
import com.jims.master.common.utils.PrintPdfUtils;
import com.jims.master.common.utils.StringUtils;
import com.jims.master.common.web.impl.BaseDto;
import com.jims.master.modules.doctor.dao.PatMasterIndexDao;
import com.jims.master.modules.doctor.dao.PatVisitDao;
import com.jims.master.modules.doctor.entity.PatMasterIndex;
import com.jims.master.modules.doctor.entity.PatVisit;
import com.jims.master.modules.nurse.dao.BedRecDao;
import com.jims.master.modules.oper.dao.ClinicItemDictDao;
import com.jims.master.modules.oper.entity.ClinicItemDict;
import com.jims.master.modules.orders.dao.OrdersDao;
import com.jims.master.modules.orders.entity.Orders;
import com.jims.master.modules.orders.vo.CountDrug;
import com.jims.master.modules.reg.utils.DateUtil;
import com.jims.master.modules.sys.dao.CompanyDao;
import com.jims.master.modules.sys.dao.DictVsClinicDao;
import com.jims.master.modules.sys.dao.OrgDeptDao;
import com.jims.master.modules.sys.entity.User;
import com.jims.master.modules.sys.utils.DeptUtils;
import com.jims.master.modules.sys.utils.DictUtils;
import com.jims.master.modules.sys.utils.UserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 医嘱Service
 *
 * @author 陈晓阳
 * @version 2017-03-27
 */
@Service
@Transactional(readOnly = true)
public class OrdersService extends CrudService<OrdersDao, Orders> {
    private SimpleDateFormat ymds = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    private SimpleDateFormat ymd = new SimpleDateFormat("yyyy-MM-dd");
    @Autowired
    private ClinicItemDictDao clinicItemDictDao;
    @Autowired
    private BedRecDao bedRecDao;
    @Autowired
    private OrdersDao ordersDao;
    @Autowired
    private PatVisitDao patVisitDao;
    @Autowired
    private CompanyDao companyDao;
    @Autowired
    private OrgDeptDao orgDeptDao;
    @Autowired
    private PatMasterIndexDao patMasterIndexDao;
    @Autowired
    private DictVsClinicDao dictVsClinicDao;

    public Orders get(String id) {
        return super.get(id);
    }

    public List<Orders> findList(Orders orders) {
        return super.findList(orders);
    }

    public Page<Orders> findPage(Page<Orders> page, Orders orders) {
        return super.findPage(page, orders);
    }

    /**
     * 费用核对查询医嘱
     * @param page
     * @param orders
     * @return
     * @author 赵宁
     */
    public Page<Orders> findOrdersPage(Page<Orders> page, Orders orders){
        orders.updateOrgId();
        List<Orders> list = ordersDao.findOrdersCheckCosts(orders);
        page.setList(list);
        page.setCount(list.size());
        return page;
    }

    /**
     * 保存医嘱
     *
     * @param orders
     * @return
     */
    @Transactional(readOnly = false)
    public Map<String, Object> saveOrders(Orders orders) {
        Map<String, Object> map = new HashMap<String, Object>();
        int result = 0;
        String clinicAndPriceId = orders.getClinicItemId();
        if ("0".equals(orders.getIsDrug()) || (StringUtils.isNotBlank(orders.getOrderClass())&&"A".equals(orders.getOrderClass()))) {
            //药品
            result += saveMain(orders);
            if("0".equals(orders.getIsPresc())){
                //todo 生成处方
            }
        } else if ("1".equals(orders.getIsDrug()) || (StringUtils.isNotBlank(orders.getOrderClass())&&!"A".equals(orders.getOrderClass()))) {
            //非药品
            ClinicItemDict clinicItemDict = clinicItemDictDao.get(clinicAndPriceId);
            if(clinicItemDict!=null){
                 if("k".equalsIgnoreCase(orders.getOrderClass())){
                     List<String> list=bedRecDao.getWardCode(orders.getPatientId(), orders.getVisitId());
                     if(list!=null&&!list.isEmpty()){
                         orders.setPerformedBy(list.get(0));
                     }
                     String nurseClass=dictVsClinicDao.findByClinicId(clinicItemDict.getId(), UserUtils.getOrgId());
                     if(StringUtils.isNotBlank(nurseClass)){
                         PatVisit patVisit=patVisitDao.get(orders.getVisitId());
                         patVisit.setNursingClass(nurseClass);
                         patVisitDao.update(patVisit);
                     }
                 }
                 orders.setPerformedBy(orders.getPerformedBy().replace(",",""));
                 orders.setOrderClass(clinicItemDict.getItemClass());
                 result += saveMain(orders);
            }
        }else if ("2".equals(orders.getIsDrug()) ||StringUtils.isBlank(orders.getOrderClass())) {
            result += saveMain(orders);
        }
        map.put("rows", result);
        map.put("ordersId", orders.getId());
        return map;
    }

    @Transactional(readOnly = false)
    public int saveMain(Orders orders) {
        orders.setIsExecute("0");
        orders.setNewDept(UserUtils.getUser().getOrgDept().getId());
        if(StringUtils.isBlank(orders.getBillingAttr())&&orders.getParent()!=null&&StringUtils.isNotBlank(orders.getParent().getId())){
            orders.setBillingAttr(dao.get(orders.getParent().getId()).getBillingAttr());
        }
        if(StringUtils.isBlank(orders.getId())){
            orders.preInsert();
            orders.updateOrgId();
            orders.setCreateDate(new Date());
            return dao.insert(orders);//保存主表
        }else{
            if(!"".equals(orders.getTempalteId()) && orders.getTempalteId() != null){
                orders.updateOrgId();
                orders.setCreateDate(new Date());
                return dao.insert(orders);
            } else {
                return dao.update(orders);
            }

        }
     }


    @Transactional(readOnly = false)
    public String saveOrder(Orders orders) {
        String ordersId = "";
        orders.setIsExecute("0");
        orders.setNewDept(UserUtils.getUser().getOrgDept().getId());
        if(StringUtils.isBlank(orders.getBillingAttr())&&orders.getParent()!=null&&StringUtils.isNotBlank(orders.getParent().getId())){
            orders.setBillingAttr(dao.get(orders.getParent().getId()).getBillingAttr());
        }
        if(StringUtils.isBlank(orders.getId())&&StringUtils.isBlank(orders.getTempalteId())){
            orders.preInsert();
            orders.updateOrgId();
             dao.insert(orders);//保存主表
            ordersId=orders.getId();
        }else{
             dao.update(orders);
            ordersId=orders.getId();
        }
        return ordersId;
    }


    /**
     * 修改医嘱状态
     *
     * @param orders
     * @return
     */
    @Transactional(readOnly = false)
    public int delete(Orders orders) {
        orders.setData();
        int resultVal = 0;
        orders=setChildrenIds(orders);
        resultVal += super.delete(orders);
        return resultVal;
    }

    private Orders setChildrenIds(Orders orders) {
        List<String> resultIds = new ArrayList<String>();
        String[] ids = orders.getId().split(",");
        if (ids == null || ids.length == 0) {
            return orders;
        }
        for (String pid : ids) {
            resultIds.add(pid);
        }
        List<String> childIds = this.ordersDao.findChildIdsByPId(resultIds);
        if (childIds != null && !childIds.isEmpty()) {
            for (String id : childIds) {
                resultIds.add(id);
            }
        }
        orders.setIds(resultIds);
        return orders;
    }

    /**
     * 跟新遗嘱开始时间
     *
     * @param resultIds
     * @return
     */
    @Transactional(readOnly = false)
    private int updateOrderStartDate(List<String> resultIds) {
        return this.ordersDao.updateOrderStartDate(resultIds, new Date());
    }

    /**
     * 医嘱药品自动补全
     *
     * @param q
     * @param limit
     * @param orgId
     * @return
     */
    public List<BaseDto> findListByParam(String q, String limit, String orgId) {
        //sqlSession.clearCache();
        return this.ordersDao.findListByParam(q, limit, orgId);
    }

    /**
     * 护士段查询医嘱信息
     *   entity.updateOrgId();
     entity.setPage(page);
     page.setList(dao.findList(entity));
     * @param ordersPage
     * @param orders
     * @return
     */
    public Page<Orders> findNurseOrders(Page<Orders> ordersPage, Orders orders) {
        orders.updateOrgId();
        orders.setPage(ordersPage);
        ordersPage.setList(this.ordersDao.findNurseOrders(orders));
        return ordersPage;
    }



    /**
     * 查询当前病区摆药医嘱
     *
     * @param wardCode
     * @param visitNo
     * @param storageId
     * @param orgId
     * @return
     */
    public List<Orders> findDispOrders(String wardCode, String visitNo, String storageId, String orgId, Integer days,String bedNo,String[] administrationes,String timeStamp) {
        String[] bedNos=null;
        String startBedNo="";
        String endBedNo="";
        if(StringUtils.isNotBlank(bedNo)){
            if(bedNo.contains(",")){
                bedNos=bedNo.split(",");
            }else if(bedNo.contains("-")){
                String[] bedNoBet=bedNo.split("-");
                if(bedNoBet!=null&&bedNoBet.length>0){
                    startBedNo=bedNoBet[0];
                    if(bedNoBet.length==2){
                        endBedNo=bedNoBet[1];
                    }
                }
            }else{
                bedNos=new String[]{bedNo};
            }
        }
        return this.ordersDao.findDispOrders(wardCode, visitNo, storageId, orgId, days,bedNos,administrationes,startBedNo,endBedNo,timeStamp);
    }

    /**
     * 根据药品统计
     *
     * @param wardCode
     * @param visitNo
     * @param storageId
     * @param orgId
     * @return
     */
    public List<CountDrug> countByDrug(String wardCode, String visitNo, String storageId, String orgId,String bedNo,String[] administrationes) {
        String[] bedNos=null;
        String startBedNo="";
        String endBedNo="";
        if(StringUtils.isNotBlank(bedNo)){
            if(bedNo.contains(",")){
                bedNos=bedNo.split(",");
            }else if(bedNo.contains("-")){
                String[] bedNoBet=bedNo.split("-");
                if(bedNoBet!=null&&bedNoBet.length>0){
                    startBedNo=bedNoBet[0];
                    if(bedNoBet.length==2){
                        endBedNo=bedNoBet[1];
                    }
                }
            }else{
                bedNos=new String[]{bedNo};
            }
        }
        return this.ordersDao.countByDrug(wardCode, visitNo, storageId, orgId,bedNos,administrationes,startBedNo,endBedNo);
    }

    /**
     * 保存摆药
     *
     * @param dispNo 摆药序号
     * @return
     */
    @Transactional(readOnly = false)
    public String dispSave(String dispNo, String storageId, Integer days) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("dispNo", dispNo);
        map.put("outMessage", "");
        map.put("storageId", storageId);
        ordersDao.dispSave(map);
        return (String) map.get("outMessage");
    }

    /**
     * 执行单查询
     * @param visitId
     * @return
     * @author 赵宁
     */
    public List<Orders> performOrders(String visitId,String type){
        return dao.getPerformOrders(visitId,type);
    }
    /**
     * 执行单打印
     * @param visitId
     * @return
     *@author 赵宁
     */
    public List<BaseDto> printPerformDrug(String visitId,String type){
        return dao.printPerformDrug(visitId,type);
    }
    /**
     * 执行单打印
     * @param patVisit,type
     * @return
     *@author CTQ
     */
    public String printExeuteReport(PatVisit patVisit,String type){
        User user = UserUtils.getUser();
        String hospital = companyDao.get(user.getOrgId()).getOrgName();
        Map map = new HashMap();
        if (StringUtils.isNotBlank(patVisit.getId())) {
            PatVisit pv =patVisitDao.get(patVisit.getId());
            int bedNo = pv.getBedRec().getBedNo();
            map.put("bedNo",bedNo);
            map.put("visitNo",pv.getVisitNo());
            map.put("name",pv.getPatVisitIndex().getName());
            map.put("hospital", hospital);
            if ("druglist".equals(type)) {
                map.put("type", "服药单");
                map.put("title", "服药");
            } else if ("transfusfuse".equals(type)) {
                map.put("type", "输液单");
                map.put("title", "输液");
            } else if ("treatment".equals(type)) {
                map.put("type", "治疗单");
                map.put("title", "治疗");
            } else if ("injection".equals(type)) {
                map.put("type", "注射单");
                map.put("title", "注射");
            }
        }
        String printDate = DateUtils.formatDate(new Date(),"yyyy-MM-dd");
        map.put("currentDate", printDate);
        List<BaseDto> ordersList = dao.printExeuteReportByStartDateTime("", patVisit.getId(), type);
        List<BaseDto> treatmentList = dao.printTreatmentReport(patVisit.getPatientId(), patVisit.getId());
        String printPath = "";
        if ("treatment".equals(type)) {//治疗
            if(treatmentList!=null&&treatmentList.size()>0){
                printPath = PrintPdfUtils.previewPdf(user.getId(), "his/nurse/exeuteReport.jasper", map, treatmentList, "treatment");
            }else{
                printPath = "暂无数据";
            }
        } else {
            if(ordersList!=null&&ordersList.size()>0){
                printPath = PrintPdfUtils.previewPdf(user.getId(), "his/nurse/exeuteDrug.jasper", map, ordersList, "orders");
            }else{
                printPath = "暂无数据";
            }

        }

        return printPath;
    }

    public List<BaseDto> automaticClinic(String q, String limit, String orgId) {
        return this.ordersDao.automaticClinic(q, limit, orgId);
    }

//    /**
//     * 预摆药查询-打印
//     * @param orders
//     * @return
//     */
//    public String dispIndexPrint(Orders orders){
//        String printPath= "";
//        String wardCode = UserUtils.getUser().getOrgDept()!=null?UserUtils.getUser().getOrgDept().getId():"";
//        String storageId = orders.getStorageId();
//        Integer days = orders.getDays();
//        Map map = new HashMap();
//        if("".equals(wardCode)){
//            wardCode = "";
//        }else {
//            OrgDept orgDept = orgDeptDao.get(wardCode);
//            orders.setDeptName(orgDept.getDeptName());
//            List<Orders> dispOrderDetails = dao.findDispOrders(wardCode, orders.getVisitNo(), storageId, UserUtils.getOrgId(), days,null,"");
//            List<CountDrug> countDrugs = new ArrayList<CountDrug>();
//            List<CountDrug> countDrugList = dao.countByDrug(wardCode,orders.getVisitNo(), storageId, UserUtils.getOrgId());
//            for (CountDrug cd : countDrugList) {
//                double amount = countAmount(cd.getClinicItemId(), dispOrderDetails);
//                if (amount <= 0) {
//                    continue;
//                }
//                cd.setAmount(amount);
//                cd.setDays(orders.getDays());
//                countDrugs.add(cd);
//            }
//
//            Date d = new Date();
//            Calendar date = Calendar.getInstance();
//            date.setTime(d);
//            date.set(Calendar.DATE, date.get(Calendar.DATE) - orders.getDays());
//
//            map.put("wardCode",orgDept.getDeptName());
//            map.put("startTime",DateUtils.formatDate(new Date(),"yyyy-MM-dd"));
//            map.put("endTime",DateUtils.formatDate(date.getTime(),"yyyy-MM-dd"));
//            map.put("printDate",new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date()));
//            printPath = PrintPdfUtils.previewPdf(UserUtils.getUser().getId(), "his/outDrug/drugDispenseClass.jasper", map, countDrugs, "drugDispenseClass");
//        }
//
//        return printPath;
//    }
    private double countAmount(String clinicItemId, List<Orders> dispOrderDetails) {
        double amount = 0;
        for (Orders order : dispOrderDetails) {
            String cId = order.getClinicItemId();
            if (clinicItemId.equals(cId)) {
                amount += order.getAmount();
            }
        }
        return amount;
    }
    /**
     * 查询未转抄的医嘱信息
     * @param orders
     * @return
     */
     public List<Orders> selectCopiedOrders(Orders orders) {
        return this.ordersDao.findNurseOrders(orders);
    }

    /**
     * 删除出院通知单医嘱
     * @param ordersId
     * @return
     */
     public int delDis(String ordersId) {
        return ordersDao.delPreDis(ordersId);
     }

    /**
     * 护理端查询医嘱瓶签信息
     * @param orders
     * @return
     * @author CTQ
     */
    public List<Orders> findOrdersBottleLabel(Orders orders){
        return ordersDao.findOrdersBottleLabel(orders);
    }

    /**
     * 护理端-医嘱瓶签-打印
     * @param orders
     * @param user
     * @return
     * @author CTQ
     */
    public String findOrdersBottleLabelPrint(Orders orders,User user){
        String printPath = "";
        Map map = new HashMap();
        List<Object> objectList  = Lists.newArrayList();
        //查询所有病人医嘱
        orders.updateOrgId();
        // List<BaseDto> ordersList = ordersDao.findOrdersBottleLabel(orders);
        List<BaseDto> orderslist = ordersDao.findListLabel(orders);
        if (orderslist!=null&&orderslist.size()>0){
            for (BaseDto bto : orderslist){
                map = new HashMap();
                String oid = bto.getAsString("id");
                PatVisit patVisit = patVisitDao.get(bto.getAsString("visitid"));
                map.put("bedNo",patVisit.getBedNo());//床号
                map.put("name",patVisit.getPatVisitIndex().getName());//
                map.put("deptname", DeptUtils.getDeptName(patVisit.getDeptStayed(),""));//所在科室
                orders.updateOrgId();
                orders.setId(oid);
                List<BaseDto> list = dao.findByOrdersId(orders);
                if(list!=null&&list.size()>0){
                    map.put("frequency",list.get(0).getAsString("frequency").trim()+"/"+list.get(0).getAsString("administration"));
                }else {
                    map.put("frequency","");
                }
                map.put("list",list);
                objectList.add(map);

            }
        }

        Map  dtoMap= new HashMap();
        if(objectList.size()<1){
            return "暂无数据";
        }else {
            dtoMap.put("SUBREPORT_DIR","his/nurse/doctorPrescription/ordersLabel_subReport.jasper");
            printPath = PrintPdfUtils.previewPdf(user.getId(), "his/nurse/doctorPrescription/ordersLabel.jasper", dtoMap, objectList, "doctorPrescription");
        }

        return printPath;
    }

    @Transactional(readOnly = false)
    public Map<String, Object> saveTreatTemplate(String id, String fTreatId, String visitId, String patientId, String prescApplyId, List<Orders> list) {
        Map<String, Object> map = new HashMap<String, Object>();
        String fId ="";
        for(int i=0;i<list.size();i++){
            Orders orders = list.get(i);
            orders.setIsApply("0");
            orders.setPatientId(patientId);
            orders.setVisitId(visitId);
            orders.setOrderStatus("0");
            if(StringUtils.isBlank(orders.getParent().getId())){
                orders.preInsert();
                fId = orders.getId();
                fTreatId = orders.getTempalteId();
            } else {
                if(orders.getParent().getId().equals(fTreatId)){
                    orders.preInsert();
                    orders.getParent().setId(fId);
                } else {
                    orders.preInsert();
//					fFlag=i;
//					fTreatId=prescriptionItem.getTempalteId();
//					fId=prescriptionItem.getId();
                }
            }
            map =saveOrders(orders);
        }
        return map;
    }
    /**
     * 护理端-医嘱信息-打印查询
     * @param orders
     * @return
     * @author CTQ
     */
    public String findNurseOrdersPrint(Orders orders){
        User user = UserUtils.getUser();
        String printPath = "";
        Map map = new HashMap();
        orders.updateOrgId();
        String hospital = companyDao.get(user.getOrgId()).getOrgName();
        if(!"".equals(orders.getPatientId()) && !"".equals(orders.getVisitId()) && !"".equals(orders.getBedNo())){
            PatMasterIndex patMasterIndex = patMasterIndexDao.get(orders.getPatientId());
            map.put("hospital", hospital);
            map.put("visitId", orders.getVisitId());
            map.put("bedNo", orders.getBedNo());
            map.put("name", patMasterIndex.getName());
            String sex = DictUtils.getDictLabel("SEX_DICT", patMasterIndex.getSex(),"");
            map.put("sex", sex);
            map.put("age", patMasterIndex.getAge());
            PatVisit patVisit = patVisitDao.get(orders.getVisitId());
            String deptName = DeptUtils.getDeptName(patVisit.getDeptAdmissionTo(),"");
            map.put("deptName", deptName);
            map.put("inpNo", patVisit.getVisitNo());
            if("1".equals(orders.getRepeatIncaditor())){ // 长期
                map.put("repeatIndicator","长期");
                List<BaseDto> ordersList = ordersDao.getDoctorOrdersPrint(orders);
                if(ordersList != null || ordersList.size()>0){
                    for(int i = 0;i< ordersList.size();i++){
                        if("7".equals(ordersList.get(i).getAsString("orderstatus"))){
                            ordersList.get(i).put("stopnurse",ordersList.get(i).getAsString("nurse"));
                        }
                    }
                    printPath = PrintPdfUtils.previewPdf(user.getId(), "his/ordersList/longOrdersList.jasper", map, ordersList, "orders");
                }else {
                    printPath = "暂无数据";
                }
            } else if ("0".equals(orders.getRepeatIncaditor())){ // 临时
                map.put("repeatIndicator","临时");
                List<BaseDto> ordersList = ordersDao.getDoctorOrdersPrint(orders);
                if(ordersList != null && ordersList.size()>0){
                    printPath = PrintPdfUtils.previewPdf(user.getId(), "his/ordersList/temporaryOrdersList.jasper", map, ordersList, "orders");
                }else {
                    printPath = "暂无数据";
                }
            }
        }
        return printPath;
    }


    /**
     * 医嘱本打印
     * @param orders
     * @return
     * @author xueliang
     */
    public String doctoradviseprint(Orders orders) {
        Map map = new HashMap();
        orders.updateOrgId();
        orders.setWardCode(UserUtils.getUser().getOrgDept().getId());
        List<BaseDto> dto = dao.finddoctoradvise(orders);
        map.put("createDate", orders.getCreateDate());
        map.put("endDate", orders.getEndDate());
        String printPath = PrintPdfUtils.previewPdf(UserUtils.getUser().getId(), "his/ordersList/ordersCopied.jasper", map, null, "ordersCopied");
        return printPath;
    }
    /**
     * 医嘱记录单打印
     * @param orders
     * @return
     */
    public String temporaryMedicalLabelPrint(Orders orders){
        Map map = new HashMap();
        orders.updateOrgId();
        orders.setWardCode(UserUtils.getUser().getOrgDept().getId());
        List<BaseDto> dtos = dao.temporaryMedicalLabelPrint(orders);
        String printPath;
        if("1".equals(orders.getOrderStatus())){//长期医嘱
            printPath = PrintPdfUtils.previewPdf(UserUtils.getUser().getId(), "his/ordersList/temporaryMedicalLabel1.jasper", map, dtos, "temporaryMedicalLabel1");
        }else {//临时医嘱
            printPath = PrintPdfUtils.previewPdf(UserUtils.getUser().getId(), "his/ordersList/temporaryMedicalLabel.jasper", map, dtos, "temporaryMedicalLabel");
        }

        return printPath;
    }

    /**
     * 摆药打印
     * @param countDrugList
     * @param wardCode
     * @return
     */
    public String dispPrint(List<CountDrug> countDrugList,String wardCode) {
        Map map = new HashMap();
        String returnVal="";
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat ymdsdf=new SimpleDateFormat("yyyy-MM-dd");
        List<BaseDto> baseDtoList=new ArrayList<BaseDto>();
        String deptName=DeptUtils.getDeptName(wardCode,"");
        String startTime=sdf.format(new Date());
       // String endTime=sdf.format(DateUtil.getDaysAfter(getNowDayZero(1), countDrugList!=null?(countDrugList.get(0).getDays() - 1):0));
        String hospital = UserUtils.getUser().getCompany().getOrgName();
        if(countDrugList!=null&&countDrugList.size()>0) {

            String endTime = sdf.format(DateUtil.getDaysAfter(getNowDayZero(1), countDrugList.get(0).getDays() - 1));
            for (CountDrug countDrug : countDrugList) {
                BaseDto baseDto = new BaseDto();
                baseDto.put("drugName", countDrug.getDrugName());
                baseDto.put("price", countDrug.getPrice());
                baseDto.put("drugSpec", countDrug.getDrugSpec());
                baseDto.put("amount", countDrug.getAmount());
                baseDto.put("drugUnits", countDrug.getDrugUnits());
                baseDto.put("firmName", countDrug.getFirmName());
                baseDto.put("deptName", deptName);
                baseDto.put("startTime", startTime);
                baseDto.put("endTime", endTime);
                baseDto.put("currentTime", sdf.format(new Date()));
                baseDtoList.add(baseDto);
            }
        }

       map.put("lists",baseDtoList);
        map.put("hospital", hospital);
        String printPath = PrintPdfUtils.previewPdf(UserUtils.getUser().getId(), "his/card/baiyaohuizong.jasper", map, baseDtoList, "baiyaohuizong");
        return returnVal;
    }

    public Date getNowDayZero(int flag) {
        String now = ymd.format(new Date());
        Date result = null;
        try {
            if (0 == flag) {
                result = ymds.parse(now + " 00:00:00");
            } else {
                result = ymds.parse(now + " 23:59:59");
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return result;
    }

    public List<BaseDto> findByUser(String category, String continue1, String valuation) {
        return ordersDao.findByUser(category,continue1,valuation);
    }
}